package com.xmy.cultivate.entity;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.xmy.cultivate.converter.LocalDateConverter;
import com.xmy.cultivate.enums.ArriveAffirmEnum;
import com.xmy.cultivate.enums.OrderTypeEnum;
import com.xmy.cultivate.enums.StatusOrderApplyEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单
 * </p>
 *
 * @author min
 * @since 2022-08-04
 */
@TableName("order_apply")
@Data
public class OrderApply implements Cloneable {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @ExcelIgnore
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 订单号
     */
    @ExcelIgnore
    private String orderNo;

    /**
     * 收据编号
     */
    @ExcelProperty(index = 0,value = "收据编号")
    private String receiptNo;

    @ExcelIgnore
    private String lklOrderNo;

    @ExcelIgnore
    private Integer lessonType;

    @ExcelIgnore
    private Integer yearClassId;

    @ExcelIgnore
    private String subjectsIdStr;

    /**
     * 应收金额
     */
    @ExcelProperty(index = 5,value = "应收/应退")
    private BigDecimal price;

    /**
     * 实收金额
     */
    @ExcelProperty(index = 7,value = "实收/实退")
    private BigDecimal solidPrice;

    /**
     * 欠费金额
     */
    @ExcelProperty(index = 8,value = "欠费")
    private BigDecimal ownPrice;

    /**
     * 是否欠费
     */
    @ExcelIgnore
    private Integer isOwn;

    /**
     * 费用类型，1收入，2支出
     */
    @ExcelIgnore
    private Integer costType;

    /**
     * 优惠金额
     */
    @ExcelProperty(index = 6,value = "优惠金额")
    private BigDecimal disPrice;

    /**
     * 学生id
     */
    @ExcelIgnore
    private Long studentId;

    /**
     * 经办校区id
     */
    @ExcelIgnore
    private Long handleSchoolId;

    /**
     * 经办校区名
     */
    @ExcelIgnore
    private String handleSchoolName;

    /**
     * 经办日期
     */
    @ExcelProperty(index = 10,value = "经办日期",converter = LocalDateConverter.class)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate handleDate;

    @ExcelIgnore
    private Long schoolId;

    @ExcelIgnore
    private Integer yearPart;

    @ExcelIgnore
    private Integer quarterNum;

    /**
     * 经办人
     */
    @ExcelIgnore
    private Long handlePersonId;

    @ExcelProperty(index = 11,value = "经办人")
    private String handlePersonName;

    @ExcelIgnore
    private LocalDate discountsDate;

    /**
     * 状态：0未确认，1确认到账，2订单作废
     */
    @ExcelIgnore
    private StatusOrderApplyEnum status;

    //1正常，2作废
    @ExcelIgnore
    private Integer abolishType;

    @TableField(exist = false)
    @ExcelProperty(index = 12,value = "状态")
    private String statusStr;

    @ExcelIgnore
    private ArriveAffirmEnum arriveAffirm;

    @ExcelIgnore
    private LocalDateTime principalDate;

    @ExcelIgnore
    private LocalDateTime financeDate;

    /**
     * 创建人
     */
    @ExcelIgnore
    @TableField(fill = FieldFill.INSERT)
    private Long createdId;

    @ExcelIgnore
    @TableLogic
    private Integer deleted;

    /**
     * 1手动确认，2自动确认
     */
//    @ExcelIgnore
//    private Integer affirmMode;

    /**
     * 订单类型：1报名，2补费，3转课，4退费，5转校
     */
    @ExcelIgnore
    private OrderTypeEnum orderType;

    @TableField(exist = false)
    @ExcelProperty(index = 3,value = "订单类型")
    private String orderTypeStr;

    /**
     * 订单类型：1报名，2补费，3转课，4退费，5转校（因为转校有两个订单，需要设置两个一样的状态，故加此字段），作废时可通些此字段，同时操作两个订单
     */
    @ExcelIgnore
    private OrderTypeEnum applyType;

    @ExcelIgnore
    private BigDecimal transferPrice;

    /**
     * 交易详情,如：八年级英语【夏季班】，2500元(30课时)*1=2500元，学费优惠100元
     * 人工智能课/口语课，99元(15课时)*1=99元
     */
    @ExcelProperty(index = 4,value = "交易内容")
    private String tradeContent;

    @ExcelIgnore
    private Integer version;

    /**
     * 报名类型：报名类型：1线下报名，2线上报名，3拉卡拉支付报名
     */
    @ExcelIgnore
    private Integer signType = 1;

    /**
     * 是否打印
     */
    @ExcelIgnore
    private Integer isPrint;

    @ExcelIgnore
    private Long payeeId;

    @ExcelIgnore
    private Integer payType;

    @ExcelIgnore
    private Integer affirmMode;

    /**
     * created_at
     */
    @ExcelIgnore
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;

    /**
     * updated_at
     */
    @ExcelIgnore
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.UPDATE)
    private LocalDateTime updatedAt;

    @ExcelIgnore
    @TableField(exist = false)
    private BigDecimal discountsPrice;

    @ExcelIgnore
    @TableField(exist = false)
    private List<OrderDetail> orderDetailList;

    @ExcelIgnore
    @TableField(exist = false)
    private List<Map<String,Object>> course;

    /**
     * deleted_at
     */
    @ExcelIgnore
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime deletedAt;

    /**
     * 转课信息详细
     */
    @ExcelIgnore
    @TableField(exist = false)
    private OrderTransfer orderTransfer;

    /**
     * 转课信息详细
     */
    @ExcelIgnore
    @TableField(exist = false)
    private List<OrderTransferDetail> orderTransferDetailList;

    /**
     * 支付类型帐号信息
     */
    @ExcelIgnore
    @TableField(exist = false)
    private List<OrderPayAccount> orderPayAccountList;

    @ExcelProperty(index = 1,value = "学生姓名")
    @TableField(exist = false)
    private String studentName;

    @ExcelIgnore
    @TableField(exist = false)
    private String linkman;

    @ExcelProperty(index = 2,value = "联系方式")
    @TableField(exist = false)
    private String linkmanPhone;

    @ExcelProperty(index = 9,value = "经办校区")
    @TableField(exist = false)
    private String schoolName;

    @ExcelIgnore
    @TableField(exist = false)
    private List<Long> phoneInviteList;

    /**
     * 邀约人列表
     */
    @ExcelIgnore
    @TableField(exist = false)
    private List<Long> inviteList;

    /**
     * 试听人列表
     */
    @ExcelIgnore
    @TableField(exist = false)
    private List<Long> auditionList;

    /**
     * 成交人列表
     */
    @ExcelIgnore
    @TableField(exist = false)
    private List<Long> bargainList;

    /**
     * 续报成交人列表
     */
    @ExcelIgnore
    @TableField(exist = false)
    private List<Long> dealList;

    /**
     * 转出校区
     */
    @ExcelIgnore
    @TableField(exist = false)
    private Long outSchoolId;

    /**
     * 学生id队列
     */
    @ExcelIgnore
    @TableField(exist = false)
    private List<Long> studentList;

    /**
     * 科目id队列
     */
    @ExcelIgnore
    @TableField(exist = false)
    private List<Long> subjectsList;

    @ExcelIgnore
    @TableField(exist = false)
    private String subjectsNames;


    @Override
    public Object clone() {
        OrderApply orderApply = null;
        try{
            orderApply = (OrderApply)super.clone();
        }catch(CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return orderApply;
    }

    @ExcelIgnore
    @TableField(exist = false)
    private String yearClassName;

    @ExcelIgnore
    @TableField(exist = false)
    private String courseName;

    /**
     * 转出班级id(记录转校时自动创建班级是否已经创建)
     */
    @ExcelIgnore
    private Long outId;

    /**
     * 转出校区详情id
     */
    @ExcelIgnore
    private Long changeSchoolDetailId;

    @ExcelIgnore
    @TableField(exist = false)
    List<Integer> affirmTypeList;

    @ExcelIgnore
    @TableField(exist = false)
    private Long readingSchoolId;

    @ExcelIgnore
    @TableField(exist = false)
    private Integer isAddLack;

    @TableField(exist = false)
    @ExcelProperty(index = 14,value = "支付状态")
    private String payTypeStr;

    @ExcelIgnore
    @TableField(exist = false)
    @ApiModelProperty("支付金额，单位为分")
    private Long totalAmount;

    @ExcelIgnore
    @TableField(exist = false)
    @ApiModelProperty("订单有效期 格式yyyyMMddHHmmss,最大支持下单时间+7天")
    private String orderEfficientTime;

    @ExcelIgnore
    @TableField(exist = false)
    @ApiModelProperty("网点名称")
    private String shopName;

    @ExcelIgnore
    @TableField(exist = false)
    @ApiModelProperty("支付链接")
    private String counterUrl;

    @ExcelIgnore
    @TableField(exist = false)
    @ApiModelProperty("退费原因Id")
    private Long causeId;
}
